home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / SAT 2.4.0 & updates ƒ / SAT-TCL and demo / SATTest / CSATTestDirector.p < prev    next >
Encoding:
Text File  |  1995-12-18  |  6.1 KB  |  239 lines  |  [TEXT/PJMM]

  1. {****************************************************}
  2. {}
  3. {        CSATTestDirector.p                                                                                                                                                                                }
  4. {}
  5. {        Director methods for the SATTest application.                                                                                                    }
  6. {}
  7. {        Copyright © 1995 by Patrick C Hew. All rights reserved.                                                                }
  8. {}
  9. {****************************************************}
  10.  
  11.  
  12. unit CSATTestDirector;
  13.  
  14. interface
  15.  
  16.     uses
  17.         TCL, SATTestIntf;
  18.  
  19. implementation
  20.  
  21.  
  22. {****************************************************}
  23. {}
  24. {        ISATTestDirector                                                                                                                                                                                        }
  25. {}
  26. {        Since the SAT director is responsible for setting up SAT, here we also give it    }
  27. {        responsibility for sound. This isn't the only way of course, for instance, we        }
  28. {        could make the application do it.                                                                                                                                                }
  29.  
  30. {****************************************************}
  31.  
  32.     procedure CSATTestDirector.ISATTestDirector (aSupervisor: CApplication);
  33.  
  34.     begin { ISATTestDirector }
  35.         ISATDirector(aSupervisor);
  36.  
  37.         gCatchSound := nil;
  38.     end; { ISATTestDirector }
  39.  
  40.  
  41. {****************************************************}
  42. {}
  43. {        Free                                                                                                                                                                                                                                }
  44. {}
  45. {        Free the SAT director class, and close down our sounds. We have to call                    }
  46. {        SATSoundShutup before deleting sounds, since deleting a sound which is                        }
  47. {        playing is bad news.                                                                                                                                                                                }
  48. {}
  49. {****************************************************}
  50.  
  51.     procedure CSATTestDirector.Free;
  52.  
  53.     begin { Free }
  54.         SATSoundShutup;
  55.  
  56.         if gCatchSound <> nil then begin
  57.                 SATDisposeSound(gCatchSound);
  58.                 gCatchSound := nil;
  59.             end; { if }
  60.  
  61.         inherited Free;
  62.     end; { Free }
  63.  
  64.  
  65. {****************************************************}
  66. {}
  67. {        BuildWindow                                                                                                                                                                                                        }
  68. {}
  69. {        We build a window which has one pane, the SAT pane. Note the use of the                    }
  70. {        existing TCL methods to fit the pane to the window.                                                                                    }
  71. {}
  72. {****************************************************}
  73.  
  74.     procedure CSATTestDirector.BuildWindow;
  75.  
  76.         var
  77.             theWindow: CWindow;
  78.             theRect: Rect;
  79.             theSATPane: CSATPane;
  80.             theScrollPane: CScrollPane;
  81.  
  82.     begin { BuildWindow }
  83.         new(theWindow);
  84.         itsWindow := theWindow;
  85.         itsWindow.IWindow(WINDSATTest, kNotFloating, gDesktop, SELF);
  86.  
  87.         NEW(theScrollPane);
  88.         theScrollPane.IScrollPane(itsWindow, SELF, 10, 10, 0, 0, sizELASTIC, sizELASTIC, kHasHScroll, kHasVScroll, kHasSizebox);
  89.         theScrollPane.FitToEnclFrame(kDoHorizontal, kDoVertical);
  90.  
  91.         SetRect(theRect, 0, 0, 461, 308);
  92.  
  93.         new(theSATPane);
  94.         itsSATPane := theSATPane;
  95.         itsSATPane.ISATPane(theScrollPane, SELF, 10, 10, 0, 0, sizELASTIC, sizELASTIC, PICTColorBackground, PICTBWBackground, theRect, kNoUseMenuBar, kNoDither4Bit, kNoBeSmart);
  96.         itsSATPane.FitToEnclosure(kDoHorizontal, kDoVertical);
  97.  
  98.         theScrollPane.InstallPanorama(itsSATPane);
  99.         theScrollPane.SetSteps(8, 8);
  100.         theScrollPane.SetOverlaps(72, 72);
  101.  
  102.         SetRect(theRect, 200, 150, 500, 350);
  103.         itsWindow.SetSizeRect(theRect);
  104.  
  105.         gDecorator.PlaceNewWindow(itsWindow);
  106.     end; { BuildWindow }
  107.  
  108.  
  109. {****************************************************}
  110. {}
  111. {        SetUpSprites                                                                                                                                                                                                        }
  112. {}
  113. {        Set up the sprites for the player and the target.                                                                                                }
  114. {}
  115. {****************************************************}
  116.  
  117.     procedure CSATTestDirector.SetUpSprites;
  118.  
  119.         var
  120.             theSpritePtr: SpritePtr;
  121.  
  122.     begin { SetUpSprites }
  123.         theSpritePtr := SATNewSprite(0, 200, 200, @SetupPlayer);
  124.         theSpritePtr := SATNewSprite(0, 0, SATRand(gSAT.offSizeV), @SetupTarget);
  125.     end; { SetUpSprites }
  126.  
  127.  
  128. {****************************************************}
  129. {}
  130. {        SetUpSprites                                                                                                                                                                                                        }
  131. {}
  132. {        Set up our"catch" sound.                                                                                                                                                                    }
  133. {}
  134. {****************************************************}
  135.  
  136.     procedure CSATTestDirector.SetUpSounds;
  137.  
  138.     begin { SetUpSounds }
  139.         gCatchSound := SATGetNamedSound('TestSound');
  140.     end; { SetUpSounds }
  141.  
  142.  
  143. {****************************************************}
  144. {}
  145. {        UpdateMenus                                                                                                                                                                                                        }
  146. {}
  147. {        Enable the "Play catch" menu command.                                                                                                                        }
  148. {}
  149. {****************************************************}
  150.  
  151.     procedure CSATTestDirector.UpdateMenus;
  152.  
  153.     begin { UpdateMenus }
  154.         inherited UpdateMenus;
  155.  
  156.         gBartender.EnableCmd(cmdPlayCatch)
  157.     end; { UpdateMenus }
  158.  
  159.  
  160. {****************************************************}
  161. {}
  162. {        DoCommand                                                                                                                                                                                                            }
  163. {}
  164. {        Check to see if we want to play a game. If so, do so.                                                                                }
  165. {}
  166. {****************************************************}
  167.  
  168.     procedure CSATTestDirector.DoCommand (theCommand: longint);
  169.  
  170.     begin { DoCommand }
  171.         if theCommand = cmdPlayCatch then begin
  172.                 PrepareForPlaying;
  173.                 DoPlay;
  174.                 FinishPlaying;
  175.             end; { if }
  176.         inherited DoCommand(theCommand);
  177.     end; { DoCommand }
  178.  
  179.  
  180. {****************************************************}
  181. {}
  182. {        PrepareForPlaying                                                                                                                                                                                    }
  183. {}
  184. {        Hide the cursor and call the inherited method to prepare the pane.                                        }
  185. {}
  186. {****************************************************}
  187.  
  188.     procedure CSATTestDirector.PrepareForPlaying;
  189.  
  190.     begin { PrepareForPlaying }
  191.         HideCursor;
  192.  
  193.         inherited PrepareForPlaying;
  194.     end; { PrepareForPlaying }
  195.  
  196.  
  197. {****************************************************}
  198. {}
  199. {        DoPlay                                                                                                                                                                                                                        }
  200. {}
  201. {        Implements a simple game loop.                                                                                                                                                }
  202. {}
  203. {****************************************************}
  204.  
  205.     procedure CSATTestDirector.DoPlay;
  206.  
  207.         const
  208.             kTicksPerFrame = 2;
  209.  
  210.         var
  211.             t: Longint;
  212.  
  213.     begin { DoPlay }
  214.         while not Button do begin
  215.                 t := TickCount;
  216.                 SATRun(false);
  217.                 while TickCount < t + kTicksPerFrame do begin
  218.                             { Nothing. }
  219.                     end; { while }
  220.             end; { while }
  221.     end; { DoPlay }
  222.  
  223.  
  224. {****************************************************}
  225. {}
  226. {        FinishPlaying                                                                                                                                                                                                        }
  227. {}
  228. {        Show the cursor.                                                                                                                                                                                            }
  229. {}
  230. {****************************************************}
  231.  
  232.     procedure CSATTestDirector.FinishPlaying;
  233.  
  234.     begin { FinishPlaying }
  235.         ShowCursor;
  236.     end; { FinishPlaying }
  237.  
  238.  
  239. end. { CSATTestDirector }